package org.mclll.xwangplugin.town.database.mapper.manage;

import com.google.common.collect.Lists;
import org.apache.ibatis.session.SqlSession;
import org.mclll.xwangplugin.datasource.MybatisConfig;
import org.mclll.xwangplugin.town.database.domain.TownShopDO;
import org.mclll.xwangplugin.town.database.mapper.TownShopMapper;

import java.util.List;

/**
 * @author: geduo
 * @date: 2023/9/22 19:44
 */
public class TownShopManage {

    public static List<TownShopDO> selectList(TownShopDO param) {
        List<TownShopDO> ret = Lists.newArrayList();
        try(SqlSession sqlSession = MybatisConfig.SQL_SESSION_FACTORY.openSession()) {
            TownShopMapper mapper = sqlSession.getMapper(TownShopMapper.class);
            ret = mapper.selectList(param);
        }
        return ret;
    }

    public static void updateByUuid(TownShopDO param) {
        try(SqlSession sqlSession = MybatisConfig.SQL_SESSION_FACTORY.openSession()) {
            TownShopMapper mapper = sqlSession.getMapper(TownShopMapper.class);
            mapper.updateByUuid(param);
            sqlSession.commit();
        }
    }

    public static void insert(TownShopDO param) {
        try(SqlSession sqlSession = MybatisConfig.SQL_SESSION_FACTORY.openSession()) {
            TownShopMapper mapper = sqlSession.getMapper(TownShopMapper.class);
            mapper.insert(param);
            sqlSession.commit();
        }
    }

    public static TownShopDO selectByUuid(String townUuid) {
        try(SqlSession sqlSession = MybatisConfig.SQL_SESSION_FACTORY.openSession()) {
            TownShopMapper mapper = sqlSession.getMapper(TownShopMapper.class);
            return mapper.selectByUuid(townUuid);
        }
    }

    public static void update(TownShopDO param, TownShopDO where) {
        try(SqlSession sqlSession = MybatisConfig.SQL_SESSION_FACTORY.openSession()) {
            TownShopMapper mapper = sqlSession.getMapper(TownShopMapper.class);
            mapper.update(param, where);
            sqlSession.commit();
        }
    }

//    public static void createTable() {
//        try(SqlSession sqlSession = MybatisConfig.SQL_SESSION_FACTORY.openSession()) {
//            TownShopMapper mapper = sqlSession.getMapper(TownShopMapper.class);
//            mapper.createTable();
//            sqlSession.commit();
//        }
//    }
}
